const str = `
    <html>
        <body>
            <div>第一个div</div>
            <p>p标签</p>
            <div>第二个div</div>
            <span>span标签</span>
        </body>
    </html>
`;

const regExp = /<div>(.*)<\/div>/g;
function selectDiv(regExp, str) {
  let matches = [];
  for (let match of str.matchAll(regExp)) {
    matches.push(match[1]);
  }
  return matches;
}
const res = selectDiv(regExp, str);
console.log(res);
